<?php


/** 
 * 举报操作
 * @author Legend. <xcx_legender@qq.com>
 * @param 
 * @return 
 */

/**
 * @apiDefine ApiErrorExample
 *
 * @apiErrorExample 失败返回
 * HTTP/1.1 200 OK
 * {
 *  "code": "",
 *  "info": "",
 *  "data": "",
 * }
 *
 */

/**
 * @apiDefine ApiSuccessExample
 *
 * @apiSuccessExample 成功返回
 * HTTP/1.1 200 OK
 * {
 *  "data": "",
 *  "info": "",
 *  "code": 200,
 * }
 * 
 */

namespace Api\Controller;

class AccuseController extends UserBaseController 
{	
	/**
	*评论的事件对象
	*/
	protected $eventObj = '';
	
		/**
	*参数初始化
	*/
	
	protected function _initialize(){
		parent::_initialize();
		$this->eventObj = A('Api/Accuse', 'Event');
	}

	
	/** 
	 * 新增举报评论信息
	 * @author Legend. <xcx_legender@qq.com>
	 * @param  $id, 评论ID  type: 1-4 类型 
	 * @return 
	 */
	
	/**
	 * @api {get}  /api/accuse/comments add accuse to comments
	 * @apiVersion 4.0.0
	 * @apiName comments
	 * @apiGroup Accuse
	 *
	 * @apiParam {String} appToken User Token
	 * @apiParam {Number} id comments ID
	 * @apiParam {Number} type accuse type
	 *
	 * @apiSuccess {String} info  show message
	 * @apiSuccess {Number} code  status code.
	 * @apiSuccess {Object} data  extend datas.
	 *
	 * @apiUse ApiSuccessExample
	 *
	 * @apiUse ApiErrorExample
	 */
	
	public function comments(){
		$id 	= I('id', 0, 'intval');
		$type 	= I('type', 0, 'intval');
		if (!$id || !$type)
		{
			$this->param_error();
		}
		$res = $this->eventObj->comments(UID, $id, $type);
		$res ? $this->success('ok') : $this->error(self::$API_ERROR['ERROR_ACCUSE'], $this->eventObj->getError() ? $this->eventObj->getError() : '提交失败');
	}

	// 举报用户
	/**
	 * @api {get}  /api/accuse/user accuse one user
	 * @apiVersion 4.0.0
	 * @apiName GetUser
	 * @apiGroup Accuse
	 *
	 * @apiParam {Number} id Users unique ID.
	 *
	 * @apiSuccess {String} info  show message
	 * @apiSuccess {Number} code  status code.
	 * @apiSuccess {Object} data  extend datas.
	 *
	 * @apiUse ApiSuccessExample
	 *
	 * @apiError UserNotFound The id of the User was not found.
	 *
	 * @apiUse ApiErrorExample
	 */
	public function user()
	{
		$nickname = I('nickname', '', 'trim');
		$type 	  = I('type', 0, 'intval');
		if (!$nickname || !$type)
		{
			$this->param_error();
		}

		$target_id = event('User')->getUser($nickname);
		if (!$target_id){
			$this->error(self::$API_ERROR['ERROR_ACCUSE'], '用户信息错误');
		}

		$res = $this->eventObj->user(UID, $target_id, $type);
		$res ? $this->success('ok') : $this->error(self::$API_ERROR['ERROR_ACCUSE'], $this->eventObj->getError() ? $this->eventObj->getError() : '提交失败');
	}


	/**
	 * @api {get}  /api/accuse/video add accuse to video
	 * @apiVersion 4.0.4
	 * @apiName video
	 * @apiGroup Accuse
	 *
	 * @apiParam {String} appToken User Token
	 * @apiParam {Number} id video ID
	 * @apiParam {Number} type accuse type
	 *
	 * @apiSuccess {String} info  show message
	 * @apiSuccess {Number} code  status code.
	 * @apiSuccess {Object} data  extend datas.
	 *
	 * @apiUse ApiSuccessExample
	 *
	 * @apiError 501 UNLOGIN user token error.
	 * @apiError 524 ERROR_ACCUSE action fail.
	 *
	 * @apiUse ApiErrorExample
	 */
	public function video()
	{
		$data = I('');
		if ( empty($data['id']) || !is_numeric($data['type']) || $data['type'] == 0 ){
			$this->param_error();
		}

		extract($data);

		$video = event('Video')->info($id);
		if (!$video){
			$this->error(self::$API_ERROR['ERROR_ACCUSE'], '视频信息错误');
		}

		$res = $this->eventObj->video(UID, $id, $type);
		$res ? $this->success('ok') : $this->error(self::$API_ERROR['ERROR_ACCUSE'], $this->eventObj->getError() ? $this->eventObj->getError() : '提交失败');

	}











}
